/*
 * @Descripttion: 
 * @version: 
 * @Author: Eugene
 * @Date: 2023-06-05 09:22:31
 * @LastEditors: Andy
 * @LastEditTime: 2023-07-03 09:54:42
 */
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/moneylog/index',
                    add_url: 'user/moneylog/add',
                    edit_url: 'user/moneylog/edit',
                    del_url: 'user/moneylog/del',
                    multi_url: 'user/moneylog/multi',
                    table: 'user_money_log',
                }
            });

            var table = $("#table");
            //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='memo']", form).addClass("selectpage").data("source", "user/moneylog/select").data("primaryKey", "name").data("field", "name").data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'user.nickname', title: __('昵称'), formatter: Table.api.formatter.search },
                        { field: 'user.mobile', title: __('手机号'), operate: 'LIKE' },
                        { field: 'user.group_id', title: __('会员'), formatter: Table.api.formatter.label, searchList: { '1': __('普通会员'), '2': __('初级会员'), '3': __('中级会员'), '4': __('高级会员') } },
                        // { field: 'user.level', title: __('星级'), formatter: Table.api.formatter.label, searchList: { '0': __('普通用户'), '1': __('经销商'), '2': __('主管'), '3': __('经理'), '4': __('高级经理'), '5': __('总监'), '6': __('总裁'), '7': __('董事') } },
                        { field: 'money', title: __('Money'), operate: false, },
                        { field: 'before', title: __('Before'), operate: false, },
                        { field: 'after', title: __('After'), operate: false, },
                        { field: 'source_type', title: __('Memo'), formatter: Table.api.formatter.label, searchList: Config.memoList },
                        { field: 'p_user.nickname', title: __('被提成昵称'), operate: false },
                        { field: 'p_user.mobile', title: __('被提成手机号'), operate: false },
                        { field: 'order_sn', title: __('来源订单'), formatter: Table.api.formatter.search },
                        { field: 'interests', title: __('分红权益'), formatter: Table.api.formatter.search },
                        { field: 'memo', title: __('备注') },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
                $("#price").text(data.extend.price);
                $("#total_interests").text(data.extend.total_interests);
                $("#unit_price").text(data.extend.unit_price);
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});